﻿@page "/FileDirectoryBrowser"
@using System.Xml

<h3>FileDirectoryBrowser</h3>

<RadzenRow>
    <RadzenColumn>
        <RadzenTree Data=@entries Expand=@LoadFiles Style="width: 100%; height: 300px" Change="ChangeSelectRecipeEvent">
@*             <RadzenTreeLevel TextProperty=@(nameof(RecipePathDto.DisplayName)) Template=@FileOrFolderTemplate ChildrenProperty=@(nameof(RecipePathDto.Childs))
                             Expanded=@(i => true)
                             HasChildren=@(i => ((RecipePathDto)i).Childs?.Any() == true) /> *@
            <RadzenTreeLevel TextProperty=@(nameof(RecipePathDto.DisplayName)) Template=@FileOrFolderTemplate HasChildren=@(i => Directory.Exists(((RecipePathDto)i).Path) == true) />
        </RadzenTree>
    </RadzenColumn>
    <RadzenColumn>

        <RadzenTree Data=@categories Expand=@OnExpand Value="currentCategory" Change="ChangeEvent">
            <RadzenTreeLevel TextProperty=@(nameof(Category.Name)) ChildrenProperty=@(nameof(Category.Childs))
                             Expanded=@(i => true)
                             HasChildren=@(i => ((Category)i).Childs?.Any() == true) />
        </RadzenTree>

    </RadzenColumn>
    <RadzenColumn Size="12" SizeMD="6">
        <RadzenCard Class="rz-my-12 rz-mx-auto">
            <RadzenStack>
                @foreach (var data in dataSource)
                {
                    <RadzenFieldset Text=@data.Name>
                        <RadzenStack Gap="1rem">

                            @foreach (var item in data.Items)
                            {
                                <RadzenRow AlignItems="AlignItems.Center">
                                    <RadzenColumn Size="12" SizeMD="4">
                                        <RadzenLabel Text=@item.Name Component="CardId" />
                                    </RadzenColumn>
                                    <RadzenColumn Size="12" SizeMD="8">
                                        <RadzenTextBox ReadOnly="true" Value=@item.Value />
                                    </RadzenColumn>
                                </RadzenRow>
                            }
                        </RadzenStack>
                    </RadzenFieldset>
                }
            </RadzenStack>
        </RadzenCard>
    </RadzenColumn>
</RadzenRow>



@code {
    private List<RecipePathDto> entries = new List<RecipePathDto>();
    protected override void OnInitialized()
    {
        entries = new List<RecipePathDto>()
        {
          new RecipePathDto
          {
               IsFloder=true,
                DisplayName="文件夹1",
                 Path="文件夹",
          } ,
           new RecipePathDto
          {
               IsFloder=true,
                DisplayName="文件2",
                 Path="文件",
          }
        };

        InitXml();
    }

    public void ChangeSelectRecipeEvent(TreeEventArgs args)
    {
        var obj = args.Value as RecipePathDto;
    }

    void LoadFiles(TreeExpandEventArgs args)
    {
        var dto = args.Value as RecipePathDto;
       
        //args.Children.Data = dto.Childs;
        args.Children.Data = Directory.EnumerateFileSystemEntries(dto.Path);
        args.Children.TextProperty = nameof(RecipePathDto.DisplayName);
        //args.Children.Text = GetTextForNode;
        //args.Children.HasChildren = (product) => false;
        args.Children.HasChildren = (path) => Directory.Exists((string)path);
        args.Children.Template = FileOrFolderTemplate;
       
    }

    string GetTextForNode(object data)
    {
        return Path.GetFileName((string)data);
    }

    RenderFragment<RadzenTreeItem> FileOrFolderTemplate = (context) => builder =>
    {
        RecipePathDto dto = context.Value as RecipePathDto;
        bool isDirectory = Directory.Exists(dto.Path);

        builder.OpenComponent<RadzenIcon>(0);
        builder.AddAttribute(1, nameof(RadzenIcon.Icon), isDirectory ? "folder" : "insert_drive_file");
        builder.CloseComponent();
        builder.AddContent(3, context.Text);
    };


    string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Recipe><PublisherName>admin</PublisherName><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424286607</CreationDate><ModificationDate>638536997424286607</ModificationDate><Name>pattern0607-Published</Name><Id>0</Id><IsPrimary>False</IsPrimary><Elements><Step ><Id>0</Id><Name>Step #1</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>27</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424426625</CreationDate><ModificationDate>638536997424426625</ModificationDate><Name>Configuration Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Configuration</ProcessTypeName><Id>700</Id><Name>MachineConfig</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >True</Value><Id>702</Id><Name>Pr IsReferenceScanNeed</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0.865540154092</Value><Id>705</Id><Name>Pr ManualCalibrationAngle</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >1</Value><Id>706</Id><Name>Pr MeasureStructureValueAnalysisType</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Configuration</ProcessTypeName><Id>710</Id><Name>GeneralSetting</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >3</Value><Id>721</Id><Name>Pr LithographyOperatingMode</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >50000</Value><Id>711</Id><Name>Pr Pgain</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >4000</Value><Id>712</Id><Name>Pr Igain</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >1.5E-06</Value><Id>713</Id><Name>Pr ImageWidth</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >1.5E-06</Value><Id>714</Id><Name>Pr ImageHeight</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>715</Id><Name>Pr ScanTime</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>716</Id><Name>Pr SetPoint</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >256</Value><Id>717</Id><Name>Pr Line</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >256</Value><Id>718</Id><Name>Pr Point</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0.5</Value><Id>719</Id><Name>Pr VibratingAmpl</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>720</Id><Name>Pr RotationAngle</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Configuration</ProcessTypeName><Id>730</Id><Name>SettingForCoarse</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >3</Value><Id>741</Id><Name>Pr LithographyOperatingMode_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >50000</Value><Id>731</Id><Name>Pr Pgain_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >4000</Value><Id>732</Id><Name>Pr Igain_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >2E-06</Value><Id>733</Id><Name>Pr ImageWidth_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >2E-06</Value><Id>734</Id><Name>Pr ImageHeight_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>735</Id><Name>Pr ScanTime_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>736</Id><Name>Pr SetPoint_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >256</Value><Id>737</Id><Name>Pr Line_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >256</Value><Id>738</Id><Name>Pr Point_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0.5</Value><Id>739</Id><Name>Pr VibratingAmpl_Coarse</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>740</Id><Name>Pr RotationAngle_Coarse</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>WaferTopology</CustomName><Id>0</Id><Name>Step #2</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>24</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424426625</CreationDate><ModificationDate>638536997424426625</ModificationDate><Name>Topology Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Topology</ProcessTypeName><Id>300</Id><Name>Wafer</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >False</Value><Id>703</Id><Name>Pr IsWaferCenteringNeed</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >wafer01</Value><Id>301</Id><Name>Pr WaferId</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >1</Value><Id>308</Id><Name>Pr WaferType</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0.3</Value><Id>303</Id><Name>Pr Wafer_D</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0.15</Value><Id>304</Id><Name>Pr Wafer_R</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>305</Id><Name>Pr NoPatternedDistance</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>306</Id><Name>Pr PreLoadAngle</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>307</Id><Name>Pr MarkTemplateConfidence</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >5</Value><Id>302</Id><Name>Pr CaseType</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >180</Value><Id>309</Id><Name>Pr WaferRotateAngle</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Topology</ProcessTypeName><Id>310</Id><Name>Shot</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0.023494787</Value><Id>311</Id><Name>Pr Shot_W</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>312</Id><Name>Pr Shot_H</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Topology</ProcessTypeName><Id>320</Id><Name>Die</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>321</Id><Name>Pr Die_W</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>322</Id><Name>Pr Die_H</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Topology</ProcessTypeName><Id>330</Id><Name>ZeroShot</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>331</Id><Name>Pr ZeroShot_Offset_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>332</Id><Name>Pr ZeroShot_Offset_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Topology</ProcessTypeName><Id>340</Id><Name>DataProcessing</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >1</Value><Id>341</Id><Name>Pr FlattenAlgorithmTypeWithNid</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >3</Value><Id>342</Id><Name>Pr FlattenAlgorithmTypeWithImage</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>343</Id><Name>Pr MeasureStructureHeight_Low</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >1</Value><Id>344</Id><Name>Pr MeasureStructureHeight_High</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>WaferMark_1</CustomName><Id>0</Id><Name>Step #3</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>25</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424426625</CreationDate><ModificationDate>638536997424426625</ModificationDate><Name>Mark Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>400</Id><Name>Shot_ID</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>401</Id><Name>Pr Mark_ShotID_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>402</Id><Name>Pr Mark_ShotID_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>410</Id><Name>MarkInfo</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value ></Value><Id>411</Id><Name>Pr MarkTempName</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>412</Id><Name>Pr MarkOffsetX</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>413</Id><Name>Pr MarkOffsetY</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>WaferMark_2</CustomName><Id>0</Id><Name>Step #4</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>25</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424426625</CreationDate><ModificationDate>638536997424426625</ModificationDate><Name>Mark Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>400</Id><Name>Shot_ID</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>401</Id><Name>Pr Mark_ShotID_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>402</Id><Name>Pr Mark_ShotID_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>410</Id><Name>MarkInfo</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value ></Value><Id>411</Id><Name>Pr MarkTempName</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>412</Id><Name>Pr MarkOffsetX</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>413</Id><Name>Pr MarkOffsetY</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>WaferMark_3</CustomName><Id>0</Id><Name>Step #5</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>25</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424426625</CreationDate><ModificationDate>638536997424426625</ModificationDate><Name>Mark Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>400</Id><Name>Shot_ID</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>401</Id><Name>Pr Mark_ShotID_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>402</Id><Name>Pr Mark_ShotID_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Mark</ProcessTypeName><Id>410</Id><Name>MarkInfo</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value ></Value><Id>411</Id><Name>Pr MarkTempName</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>412</Id><Name>Pr MarkOffsetX</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>413</Id><Name>Pr MarkOffsetY</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>WaferToiMeasurement</CustomName><Id>0</Id><Name>Step #6</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>26</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424416614</CreationDate><ModificationDate>638536997424416614</ModificationDate><Name>Measurement Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Measure</ProcessTypeName><Id>500</Id><Name>Shot_ID</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>501</Id><Name>Pr Toi_ShotID_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>502</Id><Name>Pr Toi_ShotID_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Measure</ProcessTypeName><Id>520</Id><Name>Die_ID</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >0</Value><Id>521</Id><Name>Pr DieID_X</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >0</Value><Id>522</Id><Name>Pr DieID_Y</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup><ParameterGroup ><ProcessTypeName>Measure</ProcessTypeName><Id>510</Id><Name>TOI Info</Name><IsPrimary>False</IsPrimary><Elements><Parameter ><Value >TOI-5</Value><Id>511</Id><Name>Pr Toi_Id</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >2.33E-07</Value><Id>512</Id><Name>Pr ToiOffsetX</Name><IsPrimary>False</IsPrimary></Parameter><Parameter ><Value >-1E-07</Value><Id>513</Id><Name>Pr ToiOffsetY</Name><IsPrimary>False</IsPrimary></Parameter></Elements></ParameterGroup></Elements></RecipeModule></Elements></Step><Step ><CustomName>AllExecute</CustomName><Id>0</Id><Name>Step #7</Name><IsPrimary>False</IsPrimary><Elements><RecipeModule><ChamberCapabilityId>40</ChamberCapabilityId><ChamberConfigurationName>Measurement</ChamberConfigurationName><Author>admin</Author><Description></Description><CreationDate>638536997424396606</CreationDate><ModificationDate>638536997424396606</ModificationDate><Name>Execute Module</Name><Id>0</Id><IsPrimary>True</IsPrimary><Elements><ParameterGroup ><ProcessTypeName>Test</ProcessTypeName><Id>1000</Id><Name>Test</Name><IsPrimary>False</IsPrimary></ParameterGroup></Elements></RecipeModule></Elements></Step></Elements></Recipe>";

    private void InitXml()
    {
        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xml);

        XmlNodeList steps = XmlHelper.GetNodes(xmlDocument, "//Step");

        Category stepCategory = null;
        foreach (XmlNode step in steps)
        {
            stepCategory = new Category();
            var stepNameNode = step.SelectSingleNode("CustomName | Name");
            if (stepNameNode == null)
                continue;
            stepCategory.Name = stepNameNode.InnerText;

            string xmlPath = "Elements/RecipeModule";
            XmlNodeList recipeModules = step.SelectNodes(xmlPath);

            Category recipeModuleCategory = null;
            foreach (XmlNode recipeModule in recipeModules)
            {
                recipeModuleCategory = new Category();
                var recipeModuleNode = recipeModule.SelectSingleNode("Name");
                if (recipeModuleNode == null)
                    continue;
                recipeModuleCategory.Name = recipeModuleNode.InnerText;

                xmlPath = "Elements/ParameterGroup";
                XmlNodeList parameterGroups = recipeModule.SelectNodes(xmlPath);

                // Category parameterGroupCategory = null;
                // foreach (XmlNode parameterGroup in parameterGroups)
                // {
                //     parameterGroupCategory = new Category();
                //     var parameterGroupNode = parameterGroup.SelectSingleNode("Name");
                //     if (parameterGroupNode == null)
                //         continue;

                //     parameterGroupCategory.Name = parameterGroupNode.InnerText;
                //     xmlPath = "Elements/Parameter";
                //     XmlNodeList parameters = parameterGroup.SelectNodes(xmlPath);

                //     Category parameterCategory = null;
                //     foreach (XmlNode parameter in parameters)
                //     {
                //         parameterCategory = new Category();

                //         var parameterValueNode = parameter.SelectSingleNode("Value");
                //         var parameterNameNode = parameter.SelectSingleNode("Name");
                //         if (parameterValueNode == null)
                //             continue;
                //         if (parameterNameNode == null)
                //             continue;
                //         parameterCategory.Name = parameterNameNode.InnerText;
                //         parameterCategory.Value = parameterNameNode.InnerText;

                //         parameterGroupCategory.Childs.Add(parameterCategory);
                //     }

                //     recipeModuleCategory.Childs.Add(parameterGroupCategory);
                // }

                stepCategory.Childs.Add(recipeModuleCategory);
            }

            categories.Add(stepCategory);
        }
    }

    private List<Category> categories = new List<Category>();

    private Category currentCategory { get; set; }

    void OnExpand(TreeExpandEventArgs args)
    {
        var category = args.Value as Category;

        args.Children.Data = category.Childs;
        args.Children.TextProperty = nameof(Category.Name);
        args.Children.HasChildren = (product) => false;
    }

    public void ChangeEvent(TreeEventArgs args)
    {
        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xml);
        string path = $"//Step[CustomName='{args.Text}']/descendant::ParameterGroup | //Step[Name='{args.Text}']/descendant::ParameterGroup";
        XmlNodeList groups = XmlHelper.GetNodes(xmlDocument, path);

        dataSource = new List<ItemGroup>();
        ItemGroup itemGroup = null;
        foreach (XmlNode parameterGroup in groups)
        {
            itemGroup = new ItemGroup();

            var parameterGroupNode = parameterGroup.SelectSingleNode("Name");
            if (parameterGroupNode == null)
                continue;
            itemGroup.Name = parameterGroupNode.InnerText;
            var parameters = parameterGroup.SelectNodes("Elements/Parameter");
            foreach (XmlNode parameter in parameters)
            {
                Item item = new Item();

                var parameterValueNode = parameter.SelectSingleNode("Value");
                var parameterNameNode = parameter.SelectSingleNode("Name");
                if (parameterValueNode == null)
                    continue;
                if (parameterNameNode == null)
                    continue;
                item.Name = Regex.Replace(parameterNameNode.InnerText, "Pr", "").Trim();

                item.Value = parameterValueNode.InnerText;
                itemGroup.Items.Add(item);
            }
            dataSource.Add(itemGroup);
        }
    }


    public class Category
    {
        public string Name { get; set; }

        public string Value { get; set; }

        public List<Category> Childs { get; set; } = new List<Category>();
    }

    private List<ItemGroup> dataSource = new List<ItemGroup>();

    public class ItemGroup
    {
        public string Name { get; set; }

        public List<Item> Items { get; set; } = new List<Item>();
    }

    public class Item
    {
        public string Name { get; set; }

        public string Value { get; set; }
    }

    public class RecipePathDto
    {
        public string Path { get; set; }

        public string DisplayName { get; set; }

        public bool IsFloder { get; set; } = false;

        public List<RecipePathDto> Childs { get; set; } = new List<RecipePathDto>();
    }
}
